<?php
/*
* yoTheme, a html5 wordpress theme.
*
* @licence Apache License
* @author Ethan - http://youed.me - luo123qiu@gmail.com
* 
* Project URL http://code.google.com/p/yotheme/
*/
$ua = $_SERVER['HTTP_USER_AGENT'];
/*
* htmlUA()
*/
function htmlUA($html4,$html5) {
	global $ua;
	if (strpos($ua,'MSIE 8.0')||strpos($ua,'MSIE 7.0')||strpos($ua,'MSIE 6.0')||strpos($ua,'Firefox/3')||strpos($ua,'Firefox/2')||strstr($ua,'Opera')) {
		echo $html4;
	}
	else {
		echo $html5;
	}
}
/* Regist WP menu */
register_nav_menu( 'nav-menu', 'Menu');

/**
* register_sidebar()
*
*@desc Registers the markup to display in and around a widget
*/
if ( function_exists('register_sidebar') )
{
  register_sidebar(array(
    'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '<h3>',
    'after_title' => '</h3>',
  ));
}

/* Pagenavi */
function par_pagenavi($range = 9){
	global $paged, $wp_query;
	if ( !$max_page ) {$max_page = $wp_query->max_num_pages;}
	if($max_page > 1){if(!$paged){$paged = 1;}
	if($paged != 1){echo "<li><a href='" . get_pagenum_link(1) . "' class='extend' title='Back to first page'>First</a></li>";}
	echo "<li>";
	previous_posts_link('Previous');
	echo "</li>";
    if($max_page > $range){
		if($paged < $range){for($i = 1; $i <= ($range + 1); $i++){echo "<li><a href='" . get_pagenum_link($i) ."'";
		if($i==$paged)echo "";echo ">$i</a></li>";}}
    elseif($paged >= ($max_page - ceil(($range/2)))){
		for($i = $max_page - $range; $i <= $max_page; $i++){echo "</li><a href='" . get_pagenum_link($i) ."'";
		if($i==$paged)echo "";echo ">$i</a></li>";}}
	elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
		for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){echo "<li><a href='" . get_pagenum_link($i) ."'";if($i==$paged) echo "";echo ">$i</a></li>";}}}
    else{for($i = 1; $i <= $max_page; $i++){echo "<li><a href='" . get_pagenum_link($i) ."'";
    if($i==$paged)echo " class='current'";echo ">$i</a></li>";}}
	echo "<li>";
	next_posts_link('Next');
	echo "</li>";
    if($paged != $max_page){echo "<li><a href='" . get_pagenum_link($max_page) . "' class='extend' title='Go to last page'>Last</a></li>";}}
}

function myUrl($atts, $content = null) {

extract(shortcode_atts(array(

"href" => 'http://'

), $atts));

return '<a target="_blank" href="'.$href.'" rel="nofollow">'.$content.'</a>';

}

add_shortcode("url", "myUrl");
?>